<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/axios.min.js"> </script>
    <script src="/js/query.js"></script>
    <script>
        window.onload=function (){
            setLoginInfo()
            findByItem(1);
        }
        function setLoginInfo(){
            axios.get("user/getLoginUser").then(resp=>{
             var info= resp.data
                if(info == ''){
                    $("login").innerHTML = "对不起，请先<a href='/login.html'>登陆</a>";
                }else {
                    $("login").innerHTML="欢迎光临"+info.name
                }
            })
        }
        function findByItem(pageNo){
            axios.get("product/findByItem",{
                params: {
                    pageNO:pageNo,
                    name:$("nameTxt").value
                }
            }).then(resp=>{
              var info= resp.data
               var str=""
                console.log(info.list)
                info.list.forEach(n=>{
                    str += `<div style="width: 200px;height: 300px;">
                        <img src='/img/${n.imgPath}' width="100" height="100"><br>
                        商品名：${n.name}<br>
                        单价：${n.price}<br>
                        评论：${n.speakNUm}<br>
                        <input type="button" value="查看" onclick="location.href='/speak.html?id=${n.id}'">
                        </div>`
                })
                $("productDiv").innerHTML=str;
                var cutStr = "";
                for(var i=1;i<=info.totalPage;i++){
                    cutStr += `<a href="javascript:findByItem(${i})" style="margin-left: 10px">${i}</a>`;
                }

                $("cutDiv").innerHTML = cutStr;
            })
        }
    </script>
</head>
<body>
<div id="login"></div>
<div id="productDiv" style="display: flex"></div>
<div id="cutDiv"></div>
<input type="text" name="" id="nameTxt">
<input type="button" value="搜索" onclick="findByItem(1)">
</body>
</html>